import { ajax } from '@/utils'

import {
  CheckedActivityTimeReq,
  CreateUnpackReq,
  ResultRes,
  UnpackListRes,
  UpdateStatusReq
} from './unpackTypes'

export default {
  /** 获取开箱列表 */
  getUnpackList(data): Promise<UnpackListRes> {
    return ajax.post(
      '/yswy-zy-activity/activity/back/blindbox/listByPage',
      data
    )
  },
  /** 创建开箱 */
  createUnpack(data: CreateUnpackReq): Promise<void> {
    return ajax.post(
      '/yswy-zy-activity/activity/back/blindbox/createBoxActivity',
      data
    )
  },
  /** 编辑开箱 */
  editUnpack(data: CreateUnpackReq): Promise<void> {
    return ajax.post(
      '/yswy-zy-activity/activity/back/blindbox/updateBoxActivity',
      data
    )
  },
  /** 获取开箱详情 */
  getUnpackDetail(params): Promise<CreateUnpackReq> {
    return ajax.get(
      '/yswy-zy-activity/activity/back/blindbox/getBoxActivityInfo',
      { params }
    )
  },
  /** 开箱结果 */
  getUnpackResult(data): Promise<ResultRes> {
    return ajax.post(
      '/yswy-zy-activity/activity/back/blindbox/record/listByPage',
      data
    )
  },
  /**修改开箱状态 */
  updateActivityStatus(data: UpdateStatusReq) {
    return ajax.post(
      '/yswy-zy-activity/activity/back/blindbox/updateBoxActivityStatus',
      data
    )
  },
  /** 导出开箱结果 */
  exportExcel(data) {
    return ajax.post(
      '/yswy-zy-activity/activity/back/blindbox/record/exportExcel',
      data,
      {
        responseType: 'blob',
        withResponse: true
      }
    )
  },
  /**判读当前活动时间是否可用*/
  checkActivityTime(
    data: CheckedActivityTimeReq
  ): Promise<{ result: boolean }> {
    return ajax.post(
      '/yswy-zy-activity/activity/back/blindbox/checkActivityTime',
      data
    )
  }
}
